<template>
	<view class="">
		<view class="pinglun" v-if="comments.length!== 0">
			<view class="pinglunItem" v-for="(item,index) in comments" :key="index">
				<!-- 先渲染 不是 恢复 某个 评论 的回复 -->
				<view v-if="item.beReplied.length === 0" class="plBox">
					<view class="pinglunItem-left">
						<image :src="item.user.avatarUrl" mode=""></image>
					</view>
					<view class="pinglunItem-right">
						<view class="one">
							<view class="name">
								<text>{{item.user.nickname}}</text>
								<image src="/static/huiyuan.png" mode="" v-if="item.user.vipType!==0"></image>
							</view>
							<view class="zan">
								{{item.likedCount === 0 ? '': item.likedCount}}
								<i class="iconfont icon-tuijian"></i>
							</view>
						</view>
						<view class="timer">
							{{item.time | timer}}
						</view>
						<view class="text">
							<!-- 回复的评论 -->
							<view class="text-huifu">
								{{item.content}}
							</view>
							<!-- 被回复的评论个数  采用弹框展示-->
							<view class="text-bei-huifu" v-if="item.huifu.length !== 0" @click="showPl(item)">
								{{item.huifu.length}} 条回复>
							</view>
						</view>
					</view>
					<!-- 展示的 回复别人评论  的  评论 -->
					<!-- <showPl v-if="item.huifu.length !== 0"/> -->
				</view>
			</view>
			<uni-popup type='bottom' ref="popup" :mask-click="true" class="uni-popup">
				<!-- 关闭显示层 -->
				<view>
					<view class="uni-popup-top">
						<i class="iconfont icon-cuo" @click="close()"></i>
						<text >回复({{subPlNumber}})</text>
					</view>
					<!-- show-pl 是评论的 评论，就是二级评论的组件 -->
					<show-pl :comments="subPl" />
				</view>
			</uni-popup>
		</view>
	</view>
</template>

<script>
	import moment from 'moment'
	// 引入 展示评论组件
	import showPl from './compoents/showPl.vue'
	export default {
		name: "pinglun",
		data() {
			return {
				subPl: {}, // 传给 二级 评论的数据,
				subPlNumber:0,
			};
		},
		onLoad() {
			console.log('渲染');
		},
		created() {
			// console.log('执行了~~~~~~~~');
		},
		methods: {
			showPl(item) {
				this.subPl = item
				this.subPlNumber = this.subPl.huifu.length
				console.log(this.subPl);
				this.open()
			},
			open() {
				this.$refs.popup.open('bottom')
			},
			close() {
				this.$refs.popup.close()
			}
		},
		props: {
			comments: {
				type: Array,
				default: () => []
			}
		},
		components: {
			showPl
		},
		options: {
			styleIsolation: 'shared'
		},
		filters: {
			timer: function(timer) {
				// 这个日期是 数据库传过来的
				let Time = moment(timer).format('YYYY-MM-DD')
				// 这个是今天的日期
				let NowTime = moment().format('YYYY-MM-DD')
				let day = (NowTime.substr(8, 2)) - (Time.substr(8, 2))
				if (Time === NowTime) {
					return moment(timer).format('hh : mm')
				} else if ((Time.substr(0, 4)) === (NowTime.substr(0, 4))) {
					// console.log('走了');
					// 年份一致
					if ((Time.substr(5, 2)) === (NowTime.substr(5, 2))) {
						// 月份一致
						if (day == 1) {
							// 差一天
							return '昨天' + moment(timer).format('hh : mm')
						} else {
							return moment(timer).format('YYYY年MM月DD日')
						}

					} else {
						return moment(timer).format('YYYY年MM月DD日')
					}
				} else {

					return moment(timer).format('YYYY年MM月DD日')
				}

			}
		}
	}
</script>

<style lang="scss" scoped>
	// 关于展示 二级评论的样式
	.pinglun /deep/.uni-popup__wrapper {
		height: 90vh !important;
		background-color: #FFFFFF !important;
		border-top-left-radius: 20rpx;
		border-top-right-radius: 20rpx;
		padding: 20rpx;
	}

	.pinglun {
		.uni-popup-top {
			display: flex;
			align-items: flex-end;

			i {
				font-size: 58rpx;
				color: #333333;
			}

			text {
				margin-left: 20rpx;
				font-size: 45rpx;
			}
		}
	}

	.pinglun {
		// position: relative;
		background-color: #FFFFFF;
		border-radius: 20rpx;
		padding: 20rpx;
		margin-top: 20rpx;

		.pinglunItem {

			.plBox {
				display: flex;
				padding-bottom: 20rpx;

				.pinglunItem-left {
					margin-right: 20rpx;

					image {
						width: 120rpx;
						height: 120rpx;
						border-radius: 50%;
					}
				}

				.pinglunItem-right {
					width: 100%;
					border-bottom: 1px solid #ccc;
					padding-bottom: 10rpx;

					.one {
						display: flex;
						justify-content: space-between;
						height: 50rpx;

						.name {
							font-size: 28rpx;

							image {
								margin-left: 10rpx;
								width: 70rpx;
								height: 24rpx;

							}
						}

						.zan {
							display: flex;
							font-size: 26rpx;
							color: #C0C0C0;
						}
					}

					// 时间
					.timer {
						font-size: 24rpx;
						color: #999999;
					}

					// 评论
					.text {
						padding-top: 20rpx;

						.text-huifu {
							margin-bottom: 20rpx;

						}

						.text-bei-huifu {
							color: #007AFF;
							font-size: 26rpx;
						}
					}
				}
			}

		}


	}

	// 覆盖 popup默认样式
</style>
